import pickle
from representation_learn import get_embeddings_for_sentlist
from matplotlib.axes._axes import _log as matplotlib_axes_logger
matplotlib_axes_logger.setLevel('ERROR')

name="Inform"
# name="NoOffer"
# name="Recommend"

f=open("/home/szhang/liangzi_need_smile/yyy_need_smile/visualize/data/save_testing_visual_dict.pk","rb")
data_origin=pickle.load(f)
# print(data_origin)

corpus=[]
label=[]
count=0
for item in data_origin[name]:
    corpus.append(item)
    label.append(count)
    for content in data_origin[name][item]:
        corpus.append(content)
        label.append(count)
    count+=1

corpus_tfidf=get_embeddings_for_sentlist(corpus)



from sklearn.manifold import TSNE
import matplotlib.pyplot as plt


from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
data_std = sc.fit_transform(corpus_tfidf)         #stardard

tsne = TSNE(n_components=2, learning_rate=100)
tsne.fit_transform(data_std)              #demotion


import numpy as np
data = np.array(tsne.embedding_)


label_element=set(label)
res=[]
rank=[]
for item in label_element:
    res.append([item,label.count(item)])
res.sort(key = lambda x:(x[1],x[0]),reverse = True)
for item in res:
    rank.append(item[0])



import random
temp=[]
num=0
rate=10
for item in label:
    if item not in temp:
        color_R=random.random()
        color_G=random.random()
        color_B=random.random()
        plt.scatter(data[num,0], data[num,1],marker="*",s=100,c=[color_R,color_G,color_B])
        temp.append(item) 
    else:
        final_rank=len(rank)-rank.index(item)
        # size=final_rank*rate+100
        size=100
        plt.scatter(data[num,0], data[num,1],Alpha=0.5,s=size,c=[color_R,color_G,color_B])
    num+=1

plt.savefig("/home/szhang/liangzi_need_smile/yyy_need_smile/visualize/data/pics_"+name+".png")
